<?php
namespace app\api\controller;

use Think\Upload;
use Think\Db;

class Index
{
    //测试
    public function index()
    {
    	$data = getMap("SELECT id,title FROM piece");
    	echo '<pre>';
    	print_r($data);
        return json(rs(0, 'ok', ['name'=>'xxx', 'gender'=>1, 'jwt_secret'=>config('jwt_secret')]));
    }


	//文件上传
	public function upload()
	{
		$admin_id = ADMIN_ID;
		if($admin_id < 1){
			error('请登录');
		}
		//thinkphp 5文件上传
		$file = request()->file('file');
		// 移动到框架应用根目录/uploads/ 目录下
		$info = $file->move('./upload/files/');
		if($info){
			//$ext = $info->getExtension(); 扩展名
			//$info->getFilename(); 文件名
			$file = $info->getSaveName();   //路径
			$url = 'http://'.$_SERVER['HTTP_HOST'].'/upload/files/'.$file;
			ok($url);
		}else{
			// 上传失败获取错误信息
			echo $file->getError();
		}
	}


}
